package com.tamo.ppresta.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.Gson;

import org.greenrobot.greendao.annotation.Convert;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.converter.PropertyConverter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yeyang
 * @name ppresta
 * @class name：com.tamo.ppresta.bean
 * @class describe
 * @time 2022/12/26 19:28
 * @change
 * @chang time
 * @class describe
 */
@Entity
public class GetMineInfoBean extends BaseBean implements Parcelable {

    /**
     * userMineInfo : {"personalCredit":"0","workCredit":"0","contactCredit":"0","identityCredit":"0","faceCredit":"0","bankCredit":"0","realName":"","mobile":"573101231231","pushPlatfromCount":1,"requestPlatfromCount":1,"repayPlatfromCount":0,"needRepayAllAmounts":4600,"needRepayOrderCount":2,"needRepayCount":1,"canLoanAppCount":0,"overdueRepayCount":2,"recomendStatus":0}
     * isPassProductDetailPage : 0
     * appUserCreditSort : [{"isCredit":"0","showContent":"Informacion Personal","creditType":"personalCredit"},{"isCredit":"0","showContent":"Información de la Familia","creditType":"workCredit"},{"isCredit":"0","showContent":"Información del contacto","creditType":"contactCredit"},{"isCredit":"0","showContent":"Información de identidad","creditType":"identityCredit"},{"isCredit":"0","showContent":"Información Bancaria","creditType":"bankCredit"},{"isCredit":"0","showContent":"Información de reconocimiento facial","creditType":"faceCredit"}]
     */

    @Property
    @Convert(converter = UserInfoConverter.class, columnType = String.class)
    private UserMineInfoEntity userMineInfo;
    private Integer isPassProductDetailPage;
    @Property
    @Convert(converter = AppUserCreditSortConverter.class, columnType = String.class)
    private List<AppUserCreditSortEntity> appUserCreditSort;

    @Generated(hash = 1505965579)
    public GetMineInfoBean(UserMineInfoEntity userMineInfo, Integer isPassProductDetailPage, List<AppUserCreditSortEntity> appUserCreditSort) {
        this.userMineInfo = userMineInfo;
        this.isPassProductDetailPage = isPassProductDetailPage;
        this.appUserCreditSort = appUserCreditSort;
    }

    @Generated(hash = 1540180332)
    public GetMineInfoBean() {
    }

    public UserMineInfoEntity getUserMineInfo() {
        return userMineInfo;
    }

    public void setUserMineInfo(UserMineInfoEntity userMineInfo) {
        this.userMineInfo = userMineInfo;
    }

    public Integer getIsPassProductDetailPage() {
        return isPassProductDetailPage;
    }

    public void setIsPassProductDetailPage(Integer isPassProductDetailPage) {
        this.isPassProductDetailPage = isPassProductDetailPage;
    }

    public List<AppUserCreditSortEntity> getAppUserCreditSort() {
        return appUserCreditSort;
    }

    public void setAppUserCreditSort(List<AppUserCreditSortEntity> appUserCreditSort) {
        this.appUserCreditSort = appUserCreditSort;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {

    }

    public static class UserInfoConverter implements PropertyConverter<UserMineInfoEntity, String> {
        @Override
        public UserMineInfoEntity convertToEntityProperty(String databaseValue) {
            if (databaseValue == null) {
                return null;
            }
            return new Gson().fromJson(databaseValue, UserMineInfoEntity.class);
        }

        @Override
        public String convertToDatabaseValue(UserMineInfoEntity entityProperty) {
            if (entityProperty == null) {
                return null;
            }
            return new Gson().toJson(entityProperty);
        }
    }

    public static class AppUserCreditSortConverter implements PropertyConverter<List<AppUserCreditSortEntity>, String> {
        @Override
        public List<AppUserCreditSortEntity> convertToEntityProperty(String databaseValue) {
            if (databaseValue == null) {
                return null;
            }
            String[] list_str = databaseValue.split("~");
            List<AppUserCreditSortEntity> list_transport = new ArrayList<>();
            for (String s : list_str) {
                list_transport.add(new Gson().fromJson(s, AppUserCreditSortEntity.class));
            }
            return list_transport;
        }

        @Override
        public String convertToDatabaseValue(List<AppUserCreditSortEntity> list) {
            if (list == null) {
                return null;
            } else {
                StringBuilder sb = new StringBuilder();
                for (AppUserCreditSortEntity entityProperty : list) {
                    String str = new Gson().toJson(entityProperty, AppUserCreditSortEntity.class);
                    sb.append(str);
                    sb.append("~");
                }
                return sb.toString();
            }
        }
    }

    @Override
    public String toString() {
        return "GetMineInfoBean{" +
                "userMineInfo=" + userMineInfo +
                ", isPassProductDetailPage=" + isPassProductDetailPage +
                ", appUserCreditSort=" + appUserCreditSort +
                '}';
    }
}